/* TURNOS */
USE GD2C2013
GO

INSERT INTO [vacuna_gdd].turno ( turn_id, turn_fechahora, turn_prof_id, turn_afiliado_id)
   SELECT DISTINCT ms.Turno_Numero , ms.Turno_Fecha, pr.prof_id, af.afil_id
   FROM [gd_esquema].Maestra AS ms,  [vacuna_gdd].Profesional AS pr, [vacuna_gdd].Afiliado AS af
   WHERE ms.Medico_Dni   = pr.prof_dni_persona AND
         ms.Paciente_Dni = af.afil_dni_persona AND
         ms.Turno_Numero IS NOT NULL